<?php

namespace fastphp\facade;

use fastphp\Facade;

// 修改Router门面类的middleware方法注释和实现

/**
 * Router门面类 - 提供路由管理的静态方法访问
 * 
 * @method static void rule(string $pattern, string $controller, string $action, string $name = null, string $method = 'GET') 添加路由规则
 * @method static Router get(string $pattern, string $controller, string $action, string $name = null) 添加GET路由
 * @method static Router post(string $pattern, string $controller, string $action, string $name = null) 添加POST路由
 * @method static Router put(string $pattern, string $controller, string $action, string $name = null) 添加PUT路由
 * @method static Router delete(string $pattern, string $controller, string $action, string $name = null) 添加DELETE路由
 * @method static string url(string $name, array $params = []) 根据路由名称生成URL
 * @method static mixed match(string $requestUri, string $method = null) 匹配路由
 * @method static mixed dispatch(string $requestUri) 分发请求到相应的控制器和动作
 * @method static Router middleware(string|array $middleware) 为当前路由添加中间件
 * @method static Router group(string $prefix, callable $callback) 添加路由组
 */
class Router extends Facade
{
    // 这里需要添加一个静态方法，确保链式调用能正常工作
    public static function middleware($middleware)
    {
        $instance = self::$container->get(static::getFacadeAccessor());
        $instance->middleware($middleware);
        return __CLASS__; // 返回类名，支持继续链式调用
    }
    
    protected static function getFacadeAccessor()
    {
        return 'router';
    }
}